home *** CD-ROM | disk | FTP | other *** search
- //******** Listing 6 ********************** ARRAY.HPP ****
- // ARRAY.HPP : Dynamic array example rewritten using classes
- // (c) C Gazette. See Listing 1 for usage.
- //*******************************************************/
-
- #ifndef ARRAY_HPP_
- #define ARRAY_HPP_
- #include <stdlib.h>
-
- class dynamic_array {
- int size; // remember how big it is
- int* vec; // pointer to the actual data
- void error(char *); // private error handler
- public:
- dynamic_array(size_t sz);
- ~dynamic_array();
- int& operator[] (int index) {
- if(index < 0 || index >= size) error("index out of range");
- return vec[index];
- }
- };
-
- #endif // ARRAY_HPP_